package com.wkh.project.driver.service.impl;

import com.wkh.project.common.result.Result;
import com.wkh.project.common.result.ResultCodeEnum;
import com.wkh.project.driver.client.OcrFeignClient;
import com.wkh.project.driver.service.OcrService;
import com.wkh.project.model.vo.driver.DriverLicenseOcrVo;
import com.wkh.project.model.vo.driver.IdCardOcrVo;
import com.wkh.project.service.execption.GuiguException;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class OcrServiceImpl implements OcrService {


    @Resource
    private OcrFeignClient ocrFeignClient;
    @Override
    public IdCardOcrVo idCardOcr(MultipartFile file) {
        Result<IdCardOcrVo> idCardOcrVoResult = ocrFeignClient.idCardOcr(file);
        Integer code = idCardOcrVoResult.getCode();
        if (code!=200){
            throw new GuiguException(ResultCodeEnum.SERVICE_ERROR);
        }
        return idCardOcrVoResult.getData();
    }

    //驾驶证识别
    @Override
    public DriverLicenseOcrVo driverLicenseOcr(MultipartFile file) {
        Result<DriverLicenseOcrVo> driverLicenseOcrVoResult = ocrFeignClient.driverLicenseOcr(file);
        Integer code = driverLicenseOcrVoResult.getCode();
        if (code!=200){
            throw new GuiguException(ResultCodeEnum.SERVICE_ERROR);
        }
        return driverLicenseOcrVoResult.getData();
    }
}
